//
//  ByRecordListForemanView.m
//  recordworktool_ios
//
//  Created by mc on 2017/12/19.
//  Copyright © 2017年 ZhangZhanbin. All rights reserved.
//

#import "ByRecordListForemanView.h"
#import "JSONKit.h"
@implementation ByRecordListForemanView

- (id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        CGFloat width = (SCREEN_WIDTH - 20 - 70 - 40) / 3.0;
        
        UILabel *timeLabel = [[UILabel alloc] init];
        [self addSubview:timeLabel];
        [timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(0);
            make.centerY.equalTo(self).offset(0);
            make.size.mas_equalTo(CGSizeMake(40 , 20));
        }];
        timeLabel.textAlignment = NSTextAlignmentCenter;
        timeLabel.text = @"1日";
        timeLabel.font = FONT(12);
        timeLabel.textColor = TEXT_COLOR;
        
        
        UIButton *detailBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:detailBtn];
        [detailBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self).offset(-10);
            make.centerY.equalTo(self).offset(0);
            make.size.mas_equalTo(CGSizeMake(60, 22));
        }];
        detailBtn.titleLabel.font = FONT(12);
        [detailBtn setTitle:@"明细" forState:UIControlStateNormal];
        [detailBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        detailBtn.backgroundColor = BY_THEME_COLOR;
        detailBtn.layer.cornerRadius = 10;
        
        UILabel *nameLabel = [[UILabel alloc] init];
        [self addSubview:nameLabel];
        [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(timeLabel.mas_right).offset(5);
            make.centerY.equalTo(self).offset(0);
            make.size.mas_equalTo(CGSizeMake(width - 5 + 10, 20));
        }];
        nameLabel.font = FONT(12);
        nameLabel.textColor = TEXT_COLOR;
        nameLabel.text = @"王工头";
        nameLabel.textAlignment = NSTextAlignmentCenter;
        
        UILabel *priceLabel = [[UILabel alloc] init];
        [self addSubview:priceLabel];
        [priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(detailBtn.mas_left).offset(-10);
            make.centerY.equalTo(self).offset(0);
            make.size.mas_equalTo(CGSizeMake(width - 20, 20));
        }];
        priceLabel.font = FONT(12);
        priceLabel.textColor = TEXT_COLOR;
        priceLabel.text = @"¥500";
        priceLabel.textAlignment = NSTextAlignmentCenter;
        
        
        UILabel *typeLabel = [[UILabel alloc] init];
        [self addSubview:typeLabel];
        [typeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(priceLabel.mas_left).offset(-5);
            make.centerY.equalTo(self).offset(0);
            make.left.equalTo(nameLabel.mas_right).offset(-5);
            make.height.mas_equalTo(@20);
        }];
        typeLabel.font = FONT(12);
        typeLabel.textColor = TEXT_COLOR;
        typeLabel.text = @"点工";
        typeLabel.textAlignment = NSTextAlignmentCenter;
        
        
        self.timeLabel = timeLabel;
        self.nameLabel = nameLabel;
        self.priceLabel = priceLabel;
        self.detailBtn = detailBtn;
        self.typeLabel = typeLabel;
    }
    return self;
}


- (void)setNetModel:(ByNetModel *)netModel{
    _netModel = netModel;
    
    NSString *dayStr = [_netModel.daytime substringFromIndex:6];
    self.timeLabel.text = [NSString stringWithFormat:@"%ld日", dayStr.integerValue];
    self.nameLabel.text = _netModel.worker_name;
    self.priceLabel.text = [NSString stringWithFormat:@"¥%.2f",_netModel.money.floatValue];
    NSMutableDictionary *dic;
    NSString *normal_work_time;
    if (netModel.extra && netModel.extra.length > 0 && ![netModel.extra isEqualToString:@"[]"]) {
        dic = [netModel.extra mutableObjectFromJSONString];
        normal_work_time = dic[@"normal_worktime"];
    }
    //点工
    if ([netModel.item_type_key isEqualToString:@"00S002003"]) {
        self.typeLabel.text = [NSString stringWithFormat:@"(%ld个工)点工",normal_work_time.integerValue / 8];
        self.priceLabel.textColor = GREEN_COLOR;
        self.priceLabel.text = [NSString stringWithFormat:@"+¥%.2f",_netModel.money.floatValue];
        //包工
    }else if ([netModel.item_type_key isEqualToString:@"00S002002"]){
        self.typeLabel.text = [NSString stringWithFormat:@"包工"];
        self.priceLabel.textColor = GREEN_COLOR;
        self.priceLabel.text = [NSString stringWithFormat:@"+¥%.2f",_netModel.money.floatValue];
        //借支
    }else if ([netModel.item_type_key isEqualToString:@"00S002004"]){
        self.typeLabel.text = @"借支";
        self.priceLabel.textColor = GREEN_COLOR;
        self.priceLabel.text = [NSString stringWithFormat:@"+¥%.2f",_netModel.money.floatValue];
        //结算
    }else if ([netModel.item_type_key isEqualToString:@"00S002005"]){
        self.typeLabel.text = @"结算";
        self.priceLabel.textColor = GREEN_COLOR;
        self.priceLabel.text = [NSString stringWithFormat:@"+¥%.2f",_netModel.money.floatValue];
    }
}

@end
